import service from '@/api/index'
import { notice, success } from '../utils/res.js'

const state = {
  check: {}
}

const actions = {
  async info ({ commit }, data) {
    let res = await service.info(data)
    if (res.code === 0) success(res.message)
    else notice(res.message)
    return res
  },
  async check ({ commit }, data) {
    let res = await service.check(data)
    if (res.code === 0) commit('CHECK', res.result)
    else notice(res.message)
    return res
  },
  async create ({ commit }, data) {
    let res = await service.create(data)
    if (res.code !== 0) notice(res.message)
    return res
  },
  async info ({ commit }, data) {
    let res = await service.info(data)
    if (res.code !== 0) notice(res.message)
    return res
  },
  async report ({ commit }, data) {
    let res = await service.report(data)
    if (res.code !== 0) notice(res.message)
    return res
  },
  async join ({ commit }, data) {
    let res = await service.join(data)
    if (res.code !== 0) notice(res.message)
    return res
  },
  async record ({ commit }, data) {
    let res = await service.record(data)
    if (res.code !== 0) notice(res.message)
    return res
  },
  async start ({ commit }, data) {
    let res = await service.start(data)
    if (res.code !== 0) notice(res.message)
    return res
  },
  async getrooms ({ commit }, data) {
    let res = await service.getrooms(data)
    console.log(res)
    if (res.CODE !== 1000) notice(res.MSG)
    return res
  }
}

const mutations = {
  CHECK (state, data) {
    state.check = data
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
